
import mongoDB from '../mongodb';
import $ from '../utils';

module.exports.SetComment = async function (req,res){
    let md5String = req.body.username+$.base.currentTime()+req.body.content;
    let commentId =  await $.baseFunc.md5(md5String);

    let insertData = {'username':req.body.username,'content':req.body.content,'createTime':req.body.createTime,
                      'serverTime':$.base.currentTime(),'deleteStatus':0,'daily_id':req.body.dailyId,'user_id':req.body.userId,
                      'comment_id':commentId,'to_username':req.body.toUsername,'to_userId':req.body.toUserId}

    let result = await mongoDB.mongoFunc.insertData(insertData,'f_message_comment');
    if(result){
        res.send(JSON.stringify({"status":'1',"msg":'评论成功',"dataset":[]}));
    }else{
        res.send(JSON.stringify({"status":'0',"msg":'评论失败',"dataset":[]}));
    }

}

module.exports.DeleteComment = async function (req,res){
    let queryData = {"comment_id":req.body.commentId};
    let updateData = {"deleteStatus":1};

    let result = await mongoDB.mongoFunc.updateData(queryData,updateData,'f_message_comment');

    if(result){
        res.send(JSON.stringify({"status":'1',"msg":'删除成功',"dataset":[]}))
    }else{
        res.send(JSON.stringify({"status":'0',"msg":'删除失败',"dataset":[]}))
    }

}



